/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/linked-list-cycle
   @Language: C++
   @Datetime: 19-11-19 10:26
   */

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
	bool hasCycle(ListNode *head) {
		for(ListNode *p=head; p && (p=p->next); head=head->next, p=p->next)
			if(p==head) return true;
		return false;
	}
};
